package api

import (
	"MxShop/global"
	"MxShop/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/smartwalle/alipay/v3"
	"github.com/smartwalle/xid"
)

const kServerDomain = "https://367f974b.r11.cpolar.top"

// 支付
func Pay(ctx *gin.Context) {
	//初始化
	service.AliPayClient()
	var tradeNo = fmt.Sprintf("%d", xid.Next())

	var p = alipay.TradePagePay{}
	p.NotifyURL = kServerDomain + "/alipay/notify"
	p.ReturnURL = "https://www.baidu.com"
	p.Subject = "支付测试:" + tradeNo
	p.OutTradeNo = tradeNo
	p.TotalAmount = "10.00"
	p.ProductCode = "FAST_INSTANT_TRADE_PAY"

	url, _ := global.AliPayClient.TradePagePay(p)
	ctx.JSON(200, gin.H{
		"PayUrl": url.String(),
		"msg":    "请求成功",
	})
}
